<template>
  <div class="preface-box">
    <div class="preface-content">
      <div class="preface-left">
        <div ref="prefaceLeft" style="height: 106px">
          <titles :title="props.info.text" />
          <div class="subTitle" v-if="props.info.subTitle">——{{ props.info.subTitle }}</div>
        </div>
        <div class="preface-right" ref="prefaceRight">
          <div
            v-html="getTextHtmlBr(props.info.remarks)"
            class="left-title hw-wrap-spases"
            :style="{
              fontSize: store.styleInfo.contentSize,

              color: store.styleInfo.fontColor,
            }"
          ></div>
          <div
            @click="clickPath"
            :style="{
              fontSize: store.styleInfo.mintitleSize,
              color: '#fff',
            }"
            class="left-btn flex-c-c-c"
          >
            <div class="btn-img">
              <buttonIcon />
            </div>
            <span>查看全部</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
// @ts-nocheck
import { getTextHtmlBr } from '@/utils/minxin';
import { pathList, pathListLoop } from '../route';
import { ref, onMounted, nextTick } from 'vue';
import titles from '@/components/title/title.vue';
import buttonIcon from '@/components/title/buttonIcon.vue';
import { useProjectStore } from '@/store';
import { urls } from '@/utils/request/upload';
import { useRouter, useRoute } from 'vue-router';
import UnitImageNull from '@/components/unitImageNull/unitImageNull.vue';
const prefaceLeft = ref(null);
const prefaceRight = ref(null);
const props = defineProps({
  info: {
    type: Object,
  },
});
const htmlContent = ref('');
if (props.info.remarks) {
  let arr = props.info.remarks.split('\n');
  arr.forEach((el) => {
    if (el) {
      htmlContent.value =
        htmlContent.value +
        `<span>
${el}
</span>`;
    }
  });
}

const store = useProjectStore();
const router = useRouter();
const route = useRoute();
const clickPath = () => {
  store.setchildModel(props.info);
  store.setCurrent(0);
  router.push({
    name: route.meta.loopType ? pathListLoop[8] : pathList[8],
    query: { childId: props.info.id },
  });
};

const animation1 = () => {
  nextTick(() => {
    const observer = new IntersectionObserver((entries) => {
      let canTrigger = true; // 标记是否可以触发
      entries.forEach((entry) => {
        if (entry.isIntersecting && canTrigger) {
          // 当元素进入视窗口时触发的代码
          if (prefaceLeft.value) {
            prefaceLeft.value.classList.add('animation-box');
            // 设置一个延迟时间，防止频繁触发
            canTrigger = false;
            setTimeout(() => {
              canTrigger = true;
            }, 500); // 设置延迟时间为 500 毫秒
          }
        } else {
          // if (prefaceLeft.value) {
          //   prefaceLeft.value.classList.remove('animation-box');
          // }
        }
      });
    });
    observer.observe(prefaceLeft.value);
  });
};
const animation2 = () => {
  const observer = new IntersectionObserver((entries) => {
    let canTrigger = true; // 标记是否可以触发
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger) {
        // 当元素进入视窗口时触发的代码
        prefaceRight.value.classList.add('animation-box');
        // 设置一个延迟时间，防止频繁触发
        canTrigger = false;
        setTimeout(() => {
          canTrigger = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        // prefaceRight.value.classList.remove('animation-box');
      }
    });
  });
  observer.observe(prefaceRight.value);
};
onMounted(() => {
  animation2();
  animation1();
});
</script>

<style lang="less" scoped>
@import './index.less';
.preface-box {
  // width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 1180px;
  height: auto !important;
}

.preface-content {
  display: flex;
  align-items: center;
  width: 100%;
  margin-top: 80px;
  margin-bottom: 80px;
}
.preface-left {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex: 1;
  // padding: 100px;
  .left-title {
    // text-align: center;
    text-indent: 2em;
    width: 100%;
    font-size: 16px;
    line-height: 32px;
    width: 100%;
    max-height: 192px;
    text-overflow: -o-ellipsis-lastline;
    overflow: hidden; //溢出内容隐藏
    text-overflow: ellipsis; //文本溢出部分用省略号表示
    display: -webkit-box; //特别显示模式
    -webkit-line-clamp: 6; //行数
    line-clamp: 6;
    margin-top: 0px;
    margin-bottom: 0px;
    -webkit-box-orient: vertical; //盒子中内容竖直排列
    span {
      overflow: hidden; //溢出内容隐藏
      text-overflow: ellipsis; //文本溢出部分用省略号表示
      display: -webkit-box; //特别显示模式
      -webkit-line-clamp: 6; //行数
      line-clamp: 6;
      margin-top: 0px;
      margin-bottom: 0px;
      -webkit-box-orient: vertical; //盒子中内容竖直排列
    }
  }
}
.title {
  margin-bottom: 50px;
}
.left-btn {
  margin: auto;
  margin-top: 50px;
}
.hw-wrap-spases {
  display: flex;
  flex-direction: column;
  :deep(span) {
    display: flex;
    text-indent: 2em;
    text-align: justify;
  }
}
.preface-right {
  width: 780px;
  height: 306px;
}
.preface-left {
  // height: 97px;
}
</style>
